package com.woniuxy.woniuhis.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.woniuxy.woniuhis.entity.Office;
import com.woniuxy.woniuhis.exception.OfficeServiceException;
import com.woniuxy.woniuhis.mapper.OfficeMapper;
import com.woniuxy.woniuhis.service.OfficeService;

import java.util.List;


@Service
public class OfficeServiceImpl implements OfficeService{

	@Autowired
	OfficeMapper officeMapper;

	@Override
	public void addOffice(Office office) {
		try {
			officeMapper.insertOffice(office);
		} catch (Exception e) {
			e.printStackTrace();
			throw new OfficeServiceException("系统维护中");
		}
	}

	@Override
	public void modifyOfficeInfo(Office oofice) {
		try {
			officeMapper.updateOfficeInfo(oofice);
		} catch (Exception e) {
			e.printStackTrace();
			throw new OfficeServiceException("系统维护中");
		}
	}

	@Override
	public void delOfficeByofficeId(String officeId) {
		try {
			officeMapper.deleteOfficeByofficeId(officeId);
		} catch (Exception e) {
			e.printStackTrace();
			throw new OfficeServiceException("系统维护中");
		}
	}

	@Override
	public Office findOfficeInfoByofficeId(String officeId) {
		try {
			return officeMapper.selectOfficeInfoByofficeId(officeId);
		} catch (Exception e) {
			e.printStackTrace();
			throw new OfficeServiceException("系统维护中");
		}
	}

    @Override
    public PageInfo<Office> findAllOffices(Office office,Integer pageIndex,Integer pageSize) {
		PageHelper.startPage(pageIndex,pageSize);
		try {
			List<Office> offices = officeMapper.selectAllOfficesByPage(office);
			return new PageInfo<>(offices);
		} catch (Exception e) {
			e.printStackTrace();
			throw new OfficeServiceException("系统维护中");
		}
    }

	@Override
	public List<Office> findAllOffices() {
		try {
			return officeMapper.selectAllOffices();
		} catch (Exception e) {
			e.printStackTrace();
			throw new OfficeServiceException("系统维护中");
		}
	}

}
